<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/wx/page/session.jsp"%>
<c:set var="userId" value="${param.userId}" />
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptCode" value="${param.deptCode}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<c:set var="lineId" value="${param.lineId}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>线路管理</title>
    <link rel="stylesheet" href="${ctx}/wx/css/default.css"/>
    <link rel="stylesheet" href="${ctx}/wx/css/picker.css"/>
    <script type="text/javascript" src="${ctx}/wx/js/picker.min.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/picker.data.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/LineService.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/alert.js"></script>
</head>
<body style="text-align: center;">
<form id="lineForm" name="lineForm" method="post">
    <fieldset class="contact-inner">
        <input type="hidden" id="deptId" name="deptId" value="${deptId}">
        <input type="hidden" id="lineId" name="lineId" value="${lineId}">
        <p class="contact-input">
            <input type="search" id="lineSource" name="lineSource" placeholder="出发地" onfocus="picker3(this)" required readonly>
        </p>
        <p class="contact-input">
            <input type="search" id="lineDest" name="lineDest" placeholder="目的地" onfocus="picker3(this)" required readonly>
        </p>
        <p class="contact-submit">
            <input type="button" value="保存线路" onclick="submitLine()">
        </p>
    </fieldset>
</form>
</body>
</html>
<script type="text/javascript">
    if("${lineId}" > 0) {
        var line = new Line();
        line.deptId = "${deptId}";
        line.lineId = "${lineId}";
        LineService.selectLineList(line, callbackSelectLineList);
    }
    function callbackSelectLineList(list) {
        var line = list[0];
        dwr.util.setValues(line);
    }
    function picker3(input) {
        new Picker({
            //"title": '请选择',//标题(可选)
            "defaultValue": input.value,//默认值-多个以空格分开（可选）
            "data": cityData,//数据(必传)
            "keys": {
                "id": "Code",
                "value": "Name",
                "childData": "level"//最多3级联动
            },//数组内的键名称(必传，id、text、data)
            "callBack": function (val) {
                //回调函数（val为选择的值）
                input.value = val;
            }
        });
    }
    function submitLine() {
        if (validate($("lineForm"))) {
            if("${lineId}".length > 0) {
                updateLine();
            } else {
                insertLine();
            }
        }
    }
    function insertLine() {
        var line = dwr.util.getFormValues("lineForm");
        line.lineName = line.lineSource + "至" + line.lineDest;
        LineService.insertLine(line, callback);
    }
    function updateLine() {
        var line = dwr.util.getFormValues("lineForm");
        line.lineName = line.lineSource + "至" + line.lineDest;
        LineService.updateLine(line, callback);
    }
    function callback() {
        location = "${ctx}/wx/page/line_list.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}";
    }
</script>